package sc.prototype.pfs.eventnotify.executor;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sc.prototype.pfs.eventnotify.model.Notice;
import sc.prototype.pfs.eventnotify.model.NotifyContext;
import sc.prototype.pfs.eventnotify.model.NotifyResult;
import sc.prototype.pfs.eventnotify.model.ParamKey;

/**
 * 通知处理器，实现必须是线程安全的。
 */
public abstract class NotifyExecutor {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 通知处理器外部调用通知方法，统一处理异常
     */
    public NotifyResult sendNotice(Notice notice, NotifyContext context) {
        try {
            NotifyResult rst = processSendNotice(notice, context);
            return rst;
        } catch (Exception e) {
            logger.error(context.getLogPrefix(), e);
            return NotifyResult.fail(e.getMessage());
        }
    }

    /**
     * 通知处理器内部实现方法，不用处理异常
     */
    public abstract NotifyResult processSendNotice(Notice notice, NotifyContext context) throws Exception;

    /**
     *  可用扩展参数列表
     */
    public abstract List<ParamKey> getExtParamKeys();
}
